package com.gxa.controller.dmt.user;


import com.gxa.common.R;
import com.gxa.entity.SysDepartment;
import com.gxa.service.SysDepartmentService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 用户管理
 *  1.部门管理控制类
 */
@Controller
@RequestMapping("/userManagement/deptManagement")
@Api(value = "部门管理测试",tags = "部门管理接口API")
@RequiresRoles(value = {"超级管理员"},logical = Logical.OR)
public class SysDepartmentController {

    @Autowired
    SysDepartmentService service;

    /**
     * 分页查询部门所有列表
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数默认20页
     * @return R
     */
    @ApiOperation(value = "查询所有部门列表接口",notes = "查询所有部门",
            httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @RequestMapping(value = "/findDeptList",method = RequestMethod.GET)
    @ResponseBody
    public R findDeptList(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize")Integer pageSize ){

        return service.selectAllDept(currentPage,pageSize);
    }



    /**
     * 查询部门所有列表
     */
    @ApiOperation(value = "下拉查询所有部门列表接口",notes = "下拉查询所有部门",
            httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @RequestMapping(value = "/findDeptList1",method = RequestMethod.GET)
    @ResponseBody
    public R findDeptList(){
        return service.selectAllDept();
    }

    /**
     * 添加部门信息
     * @param sysDepartment 部门实体（前端传一个json）
     * @return R
     */
    @ApiOperation(value = "添加部门接口(若添加子部门需要传PID)",notes = "添加部门(若添加子部门需要传PID)",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @RequestMapping(value = "/addDept",method = RequestMethod.POST)
    @ResponseBody
    public R addDept(@RequestBody @ApiParam(name = "sysDepartment",value = "部门实体",required = true) SysDepartment sysDepartment){
        return service.addDepartment(sysDepartment);
    }


    /**
     * 根据部门名称模糊查询
     * @param currentPage 当前页
     * @param pageSize 每页大小
     * @param depName 部门名称
     * @return R
     */
    @ApiOperation(value = "根据部门名称模糊查询",notes = "根据部门名称模糊查询",
            httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "depName",value = "部门名称",paramType = "query",dataType = "String",required = true)
    })
    @RequestMapping(value = "/findDeptByName",method = RequestMethod.GET)
    @ResponseBody
    public R findDeptByName(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize")Integer pageSize ,@RequestParam("depName")String depName){
        return service.findDepartmentByName(currentPage,pageSize,depName);
    }




    /**
     * 根据部门ID修改部门信息
     * @param sysDepartment 部门实体（前端传一个json）
     * @return  R
     */
    @ApiOperation(value = "根据部门ID修改部门信息",notes = "根据部门ID修改部门信息",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @RequestMapping(value = "/updateDeptById",method = RequestMethod.POST)
    @ResponseBody
    public R updateDeptById(@RequestBody @ApiParam(name = "sysDept",value = "部门实体",required = true) SysDepartment sysDepartment){
        return service.updateDeptById(sysDepartment);
    }


    /**
     * 根据部门Id回显部门信息
     * @param depId 部门ID
     * @return R
     */
    @ApiOperation(value = "根据部门Id回显部门信息",notes = "根据部门Id回显部门信息",
            httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "depId",value = "部门ID",paramType = "query",dataType = "String",required = true)
    })
    @RequestMapping(value = "/showDeptById",method = RequestMethod.GET)
    @ResponseBody
    public R showDeptById( @RequestParam("depId")Integer depId){
        return service.getDepartmentById(depId);
    }


    /**
     * 实现部门上移，修改部门排序
     * @param depId 部门ID
     * @return R
     */
    @ApiOperation(value = "实现部门上移",notes = "修改部门排序",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "depId",value = "部门ID",paramType = "query",dataType = "String",required = true)
    })
    @RequestMapping(value = "/addSortById",method = RequestMethod.POST)
    @ResponseBody
    public R addSortById( @RequestParam("depId")Integer depId){
        return service.addSortById(depId);
    }


    /**
     * 实现部门下移，修改部门排序
     * @param depId 部门ID
     * @return R
     */
    @ApiOperation(value = "实现部门下移",notes = "修改部门排序",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "depId",value = "部门ID",paramType = "query",dataType = "String",required = true)
    })
    @RequestMapping(value = "/subSortById",method = RequestMethod.POST)
    @ResponseBody
    public R subSortById( @RequestParam("depId")Integer depId){
        return service.subSortById(depId);
    }



    /**
     * 根据部门Id删除部门
     * @param depId 部门ID
     * @return R
     */
    @ApiOperation(value = "根据部门Id删除部门",notes = "根据部门Id删除部门",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "depId",value = "部门ID",paramType = "query",dataType = "String",required = true)
    })
    @RequestMapping(value = "/delDeptById",method = RequestMethod.POST)
    @ResponseBody
    public R delDeptById( @RequestParam("depId")Integer depId){
        return service.delDeptById(depId);
    }



}
